// $codepro.audit.disable declareAsInterface
/**Patient presenter**/
// $codepro.audit.disable accessorMethodNamingConvention, expressionValue
package edu.gatech.presenters;

import java.util.ArrayList;

import javax.swing.JOptionPane;

import edu.gatech.datastorage.Invoice;
import edu.gatech.gui.AppointmentPanel;
import edu.gatech.userclasses.Patient;

/** Evaluates the patient GUI
 * 
 * @author Tyler Natoli
 * @version 1.0
 */
public class PatientPresenter {

	/**Patient that logged in**/
	private final Patient currentPatient;
	
	/**Sets the logged in patient
	 * 
	 * @param currentPatient
	 */
	public PatientPresenter(Patient currentPatient){
		this.currentPatient = currentPatient;
	}
	
	/**
	 * Creates an appointment for the patient
	 */
	public void setAppointment(){
		if(currentPatient.getInfo().hasPendingAppointment()){
			JOptionPane.showMessageDialog(null, "You currently have a pending" +
					" appointment." +
					" Please wait to schedule your next appointment after attending" +
					" your current one");
		}
		else{
			final AppointmentPanel panel = new AppointmentPanel(currentPatient); // $codepro.audit.disable staticInstantiation, variableUsage
		}
	}
	
	/**
	 * view an appointment
	 */
	public void viewAppointment(){
		final ArrayList<String> appointments = 
			(ArrayList<String>) currentPatient.viewAppointments();
		String listOfAppointments = "";
		for(int i = 0; i < appointments.size(); i++){
			listOfAppointments = listOfAppointments + appointments.get(i) + "\n"; // $codepro.audit.disable stringConcatenationInLoop
		}
		JOptionPane.showMessageDialog(null, listOfAppointments);
	}
	
	/**
	 * Displays the patient information
	 */
	public void displayInfo(){
		JOptionPane.showMessageDialog(null, currentPatient.getInfo().toString());
	}
	
	/**
	 * Shows the latest bill for a patient
	 */
	public void viewBill(){
		Invoice invoice = currentPatient.getInfo().getLastRecord().getInvoice();
		if(invoice == null){
			JOptionPane.showMessageDialog(null, "No pending bills!");
		}
		else{
			String bill = invoice.printBill();
			JOptionPane.showMessageDialog(null, bill);
		}
	}
	
	/** Overrides toString
	 * @return String
	 */
	public String toString(){
		return "Patient presenter";
	}
}
